<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<jsp:include page="/all/base.jsp" />
<html>
<head>
	<script type="text/javascript"
		src="${contextPath}/js/template_submit.js"></script>
	<script type="text/javascript">
        $(function () {
        	$.post(m_role_find_url, function(data) {
                var items = data.rows;
                $('#roleId').combobox({  
            	    data:items,  
            	    valueField:'id',  
            	    textField:'nickname'  
            	});
                $('#roleId').combobox("select", items[0].id);
                $.post(m_res_find_url, function(data) {
                    var items = data.rows;
                    $('#resourceId').combobox({  
                	    data:items,  
                	    valueField:'id',  
                	    textField:'url'  
                	});
                    $('#resourceId').combobox("select", items[0].id);
                    // _bindControls为绑定控件方法，参数为输入框等控件的ID，提交页面时会用到这些控件
                	_bindControls(['id', 'roleId', 'resourceId']);
                	var id = '${param.id}';
                	if (typeof(id) != "undefined" && id != null && id.trim() != "") {
                		var param = {id:'${param.id}'};
                		// _loadData为加载当前页面需要数据，得到的数据会显示在_bindControls绑定的控件中
                		// 其中url为加载数据的路径，param为加载数据需要的参数，第三个参数为对加载的数据进行处理
                		// 当加载数据得到的值中属性名与_bindControls绑定的控件ID一致时可无需传此参数
                		_loadData(m_role_res_find_url, param, function(data) {
                			$('#roleId').combobox('setValue', data.role.id);
                			$('#resourceId').combobox('setValue', data.resource.id);
                		});
                    }
                });
        	});
        });
        function f_submit() {
            // 提交页面数据到指定URL，参数为url，_bindControls绑定的控件的值会提交到该url
            var param = new Object();
            param.id = $('#id').val();
            param.roleId = $('#roleId').combobox('getValue');
            param.resourceId = $('#resourceId').combobox('getValue');
            _submitChange(m_role_res_saveOrUpdate_url, param);
        }
    </script>
</head>
<body style="padding: 10px">
<form id="save_or_update_form" method="post">
	<input id="id" type="hidden" name="id" value="${param.id}"/>
	<table cellpadding="0" cellspacing="10" class="l-table-edit">
		<tr>
			<td align="right">用户角色:</td>
			<td align="left"><input id="roleId" name="roleId" style="width:160px" editable="false">
			</select>
			</td>
		</tr>
		<tr>
			<td align="right">访问权限:</td>
			<td align="left"><select id="resourceId" name="resourceId" style="width:160px" editable="false" class="easyui-combobox">
			</select>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><a href="#" id="submitBtn" class="easyui-linkbutton" iconCls="icon-ok" style="padding-left:5px;" onclick="f_submit()">提交</a>
			<a href="#" id="resetBtn" class="easyui-linkbutton" align="right" iconCls="icon-cancel" onclick="_onCancel()">取消</a></td>
		</tr>
	</table>
</form>
</body>
</html>